/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewApplet.java
 *
 * Created on 14.04.2011, 11:00:03
 */

package dischargesimulation.test;

import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.universe.SimpleUniverse;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.media.j3d.Alpha;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.RotationInterpolator;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.swing.JOptionPane;
import javax.vecmath.AxisAngle4d;
import javax.vecmath.Vector3f;

/**
 *
 * @author rybakov
 */
public class Applet3Dtest extends java.applet.Applet {

   Canvas3D canvas;
   TransformGroup last_tg;
            
    class B1Action implements  ActionListener{
        public void actionPerformed(ActionEvent e) {
//          Transform3D t =   last_tg.gett

//           last_tg.setTransform(new Transform3D(new Vector3f(0.1,)));
        }
    }


 public void init3(){
     try{
       setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse
        .getPreferredConfiguration();

    canvas = new Canvas3D(config);
    Button b = new Button("This is the top");

    b.addActionListener(new B1Action());

    add("North", b);
    add("Center", canvas);
    add("South", new Label("This is the bottom"));
    BranchGroup contents = new BranchGroup();
    ColorCube cu = new ColorCube(0.001);
    contents.addChild(cu);


    BranchGroup group = new BranchGroup();

   // X axis made of spheres
   

   for (float x = -0.5f; x <= 0.5f; x = x + 0.1f)

   {

//      Sphere sphere = new Sphere(0.05f);
      ColorCube cu1 = new ColorCube(0.01f);
      
      TransformGroup tg = new TransformGroup();
      last_tg = tg;
      Transform3D transform = new Transform3D();

      Vector3f vector = new Vector3f( x, .0f, .0f);

      transform.setTranslation(vector);

      transform.setRotation(new AxisAngle4d(1+x, 1, 1, 1));

      tg.setTransform(transform);

      tg.addChild(cu1);

      group.addChild(tg);

   }
    contents.addChild(group);

    SimpleUniverse universe = new SimpleUniverse(canvas);
    universe.getViewingPlatform().setNominalViewingTransform();

    universe.addBranchGraph(contents);
     }catch(Exception e){
         JOptionPane.showInputDialog(e.toString());
     }
 }

    /** Initializes the applet NewApplet */
    public void init() {
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    initComponents();
                    init3();
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /** This method is called from within the init() method to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setLayout(new java.awt.BorderLayout());
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
